// pages/pforward/pforward.js
var api = require('../../config/api.js');
var util = require('../../utils/util.js');
var app = getApp()
var sliderWidth = 110; // 需要设置slider的宽度，用于计算中间位置
Page({

  /**
   * 页面的初始数据
   */
  data: {

    tabs: ["申请提现", "提现明细", ],
    activeIndex: 0,
    sliderOffset: 0,
    sliderLeft: 0,

    radioItems: [{
        img: '/images/distrubution/wechatpay.png ',
        name: '微信付款',
        value: '0',
        checked: true
      },
      {
        img: '/images/distrubution/bankpay.png ',
        name: '银联付款',
        value: '1',

      }
    ],
    bank: true,

    profitlsit: [], //提现列表
    daymore: 0.00, //当日提现
    mothmore:0.00, //当月提现
    actulmore: 0.00, //总提现
    allowprf: 0.00,//可提现
    

  },

  tabClick: function(e) {
    this.setData({
      sliderOffset: e.currentTarget.offsetLeft,
      activeIndex: e.currentTarget.id
    });

  },

  radioChange: function(e) {
    let that = this
    console.log('radio发生change事件，携带value值为：', e.detail.value);

    var radioItems = this.data.radioItems;
    for (var i = 0, len = radioItems.length; i < len; ++i) {
      radioItems[i].checked = radioItems[i].value == e.detail.value;
    }

    this.setData({
      radioItems: radioItems
    });

    if (e.detail.value == 1) {
      that.setData({
        bank: false
      });
    } else {
      that.setData({
        bank: true
      })
    }


  },

  //获取提现明细
  getPrwList: function() {
    var that = this
    var url = api.GetMoneyInfo
    util.req( url, {}, "POST").then(function(res) {
      wx.showLoading({
        title: '加载中',
      })
      if (res.success) {
        var list = res.obj.outAccessDetailedList
        for(var i=0; i<list.length; i++){
          var mo = list[i].money 
            list[i].money = mo.toFixed(2)
        }
        var allow = (res.obj.srzje - res.obj.txzje).toFixed(2)
        that.setData({
          allowprf: allow,  //可提
          profitlsit: list,
          daymore: res.obj.dttx.toFixed(2), //当日提现
          mothmore: res.obj.dytx.toFixed(2), //当月提现
          actulmore: res.obj.txzje.toFixed(2), //总提现
        })
      }
      wx.hideLoading()
    }).catch(function(res) {
      wx.hideLoading()
      console.log("获取数据失败！")
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

    var that = this;
    wx.getSystemInfo({
      success: function(res) {
        that.setData({
          sliderLeft: (res.windowWidth / that.data.tabs.length - sliderWidth) / 2,
          sliderOffset: res.windowWidth / that.data.tabs.length * that.data.activeIndex
        });
      }
    });

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getPrwList()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  }
})